home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / database / msgobj10.zip / MSGOBJAD.CPP < prev    next >
C/C++ Source or Header  |  1993-02-21  |  2KB  |  111 lines

  1. // MSGOBJAD.CPP: module to handle fidonet addresses
  2.  
  3. #include <ctype.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include "config.h"
  8. #include "msgobj.h"
  9.  
  10. int address_class::parse_uucp(char *buff,char*id,char*in)
  11. {
  12.   char *z,*z2;
  13.   z=strstr(buff,in);
  14.   if(z)
  15.     {
  16.       z+=strlen(in); z2=uucp;
  17.       while(*z>32)
  18.         *(z2++)=*(z++);
  19.       *z2=0; z2=id;
  20.       while(*z && *z!=10 && *z!=13 && *z!='(')
  21.         z++;
  22.       if(*z=='(')
  23.         {
  24.           z++;
  25.           while(*z && *z!=10 && *z!=13 && *z!=')')
  26.             *(z2++)=*(z++);
  27.           *z2=0;
  28.         }
  29.       return 0;
  30.     }
  31.   return 1;
  32. }
  33.  
  34. int address_class::parse(char*s)
  35. {
  36.   char *z,*z2;
  37.   zone=net=node=point=*domain=0;
  38.   *uucp=0;
  39.   if(*s)
  40.     {
  41.       if(isdigit(*s))
  42.         {
  43.           if((z2=strchr(s,':'))!=NULL)
  44.             {
  45.               zone=atoi(s);
  46.               z2++;
  47.             }
  48.           if((z=strchr(z2,'/'))!=NULL)
  49.             {
  50.               net=atoi(z2);
  51.               z2=z+1;
  52.             }
  53.           else
  54.             return -1;
  55.           if(isdigit(*z2))
  56.             node=atoi(z2);
  57.           else
  58.             return -1;
  59.           if((z=strchr(z2,'.'))!=NULL)
  60.             point=atoi(z+1);
  61.           else
  62.             point=0;
  63.           if((z=strchr(z,'@'))!=NULL)
  64.             {
  65.               z2=z+1;
  66.               z=domain;
  67.               while(*z2 && *z2!=')' && *z2!=13 && *z2!=10 && *(unsigned char*)z2!=141)
  68.                 *z++=*z2++;
  69.               *z=0;
  70.             }
  71.         }
  72.       else
  73.         strcpy(uucp,s);
  74.       return 0;
  75.     }
  76.   return 1;
  77. }
  78.  
  79. int address_class::pack(char*s)
  80. {
  81.   char t[30];
  82.   if(*uucp)
  83.     sprintf(s,"%s",uucp);
  84.   else
  85.     {
  86.       if(!zone && !net && !node)
  87.         return -1;
  88.       if(zone)
  89.         sprintf(s,"%d:",zone);
  90.       else
  91.         *s=0;
  92.       sprintf(t,"%d/%d.%d",net,node,point);
  93.       strcat(s,t);
  94.       if(*domain)
  95.         {
  96.           strcat(s,"@");
  97.           strcat(s,domain);
  98.         }
  99.     }
  100.   return 0;
  101. }
  102.  
  103. address_class::address_class(void)
  104. {
  105.   zone=net=node=point=*domain=*uucp=0;
  106. }
  107.  
  108. address_class::~address_class(void)
  109. {
  110. }
  111.